<%--
  Created by IntelliJ IDEA.
  User: Administrator
  Date: 2021/7/23
  Time: 10:59
  To change this template use File | Settings | File Templates.
--%>
<%@ page contentType="text/html;charset=UTF-8" language="java" %>
<!DOCTYPE html>
<html>
<head>
    <meta charset="utf-8">
    <title></title>
    <link rel="stylesheet" type="text/css" href="../../css/reset.css"/>
    <link rel="stylesheet" type="text/css" href="../../css/add.css"/>

</head>
<body>
<div id="app" style="display: block">
    <div class="header">
        <span>修改快递信息</span>
    </div>
    <div class="content">
        <table>
            <tr>
                <td class="text-right">运单号</td><td class="content_right"><input class="input inline-input" name="number" placeholder="请输入运单号码" > <span class="btn btn-info" onclick="form01Submit()">立即查找</span></td>
            </tr>
        </table>
    </div>


    <div class="header">
        <span>查找信息如下</span>
    </div>
    <div class="content" id="content" >
        <table >
            <tr>
                <td class="text-right">快递单号</td><td class="content_right"><input class="input"  placeholder="请输入快递单号"  onblur="numberTest()"><button hidden disabled></button></td>
            </tr>
            <tr>
                <td class="text-right">快递公司</td><td class="content_right"><input class="input" placeholder="请输入快递公司" ></td>
            </tr>
            <tr>
                <td class="text-right">收货人姓名</td><td class="content_right"><input class="input" placeholder="请输入收货人姓名" onblur="userTest()"><button hidden disabled></button></td>
            </tr>
            <tr>
                <td class="text-right">手机号码</td><td class="content_right"><input class="input" placeholder="请输入手机号码" onblur="phoneTest()"><button hidden disabled></button></td>
            </tr>
            <tr>
                <td class="text-right">快递状态</td><td class="content_right"><input type="radio" name="status" id="radioOne" value="已签收" >已签收  <input name="status" type="radio" id="radioTwo" checked value="未签收">未签收</td>
            </tr>
            <tr>
                <td></td><td class="content_right"><span class="btn btn-info" onclick="form02Submit()" >立即修改</span> <span class="btn" onclick="reset()">重置</span> </td>
            </tr>
        </table>
    </div>
</div>
<script src="../../js/jquery-1.11.1.js"></script>
<script src="../../layer/layer.js"></script>
<script src="../../assets/layui.all.js"></script>
<script>
    $(function () {
        reset();
    });
    function reset() {
        $("input").val("");
        $("#content").css("display","none");
    }
    function form01Submit () {
        var windowId = layer.load();
        var num = $("input:eq(0)").val();
        num=$.trim(num);
        $.post("/delivery/findDelivery.do",{
            number:num
        },function (data) {
            layer.close(windowId);
            if(data["msgCode"]==200){
                $("#content").css("display","");
                $("input:eq(1)").val(data["dataList"][0]["deliveryNum"]);
                $("input:eq(2)").val(data["dataList"][0]["deliveryCompany"]);
                $("input:eq(3)").val(data["dataList"][0]["deliveryAcceptor"]);
                $("input:eq(4)").val(data["dataList"][0]["acceptorPhone"]);
                console.log(0);
                if($.trim("存放中") == $.trim(data["dataList"][0]["deliveryState"])){
                    console.log(1);
                    $("#radioTwo").prop("checked", "checked");
                }else if($.trim("被取出") == $.trim(data["dataList"][0]["deliveryState"])){
                    console.log(2);
                    $("#radioOne").prop("checked", "checked");
                }
                console.log(3);
                layer.alert("成功查寻到此快递！٩(๑>◡<๑)۶ ");
            }else if (data["msgCode"]==400){
                layer.alert("未查到此快递！(〒︿〒)");
            }
        },"json");
        return false;
    }
    function form02Submit() {
        var windowId = layer.load();
        var num = $.trim($("input:eq(0)").val());
        var company = $.trim($("input:eq(2)").val());
        var name = $.trim($("input:eq(3)").val());
        var phone = $.trim($("input:eq(4)").val());
        var status = $.trim($("input:radio:checked").val());
        $.post("/delivery/update.do",{
            deliveryNum:num,
            deliveryCompany:company,
            acceptorName:name,
            acceptorPhone:phone,
            deliveryStatus:status
        },function (data) {
            layer.close(windowId);
            if (data["msgCode"] == 200){
                layer.alert("修改成功~   ヾ(^Д^*)/");
            }else {
                layer.alert("修改失败了  (；´д｀)ゞ");
            }
        },"json");
        return false;
    }
</script>
<script>
    function numberTest () {
        var str = $("input:eq(1)").val();
        str=$.trim(str);
        var ret = /^[A-Za-z0-9-]{4,35}$/;//此处待修改
        if (!ret.test(str)) {
            $("button:eq(0)").html("快递单号不合法或已存在！");
            $("button:eq(0)").css("display","inline-block");
            $("button:eq(0)").css("color","red");
            $("button:eq(0)").css("font-size","28");
            return false;
        }
        $.getJSON("/delivery/findByDeliveryNum.do",{deliveryNum:str},function (data) {
            if(data["msgCode"]==400){
                $("button:eq(0)").html("正确");
                $("button:eq(0)").css("display","inline-block");
                $("button:eq(0)").css("color","green");
                $("button:eq(0)").css("font-size","28");
                return true;
            }else {
                $("button:eq(0)").html("已存在");
                $("button:eq(0)").css("display","inline-block");
                $("button:eq(0)").css("color","red");
                $("button:eq(0)").css("font-size","28");
            }
            return false;
        });
    }
    function userTest () {
        var str = $("input:eq(3)").val();
        str=$.trim(str);
        var ret = /^[\u4e00-\u9fa5]{2,6}$/;
        if (!ret.test(str)) {
            $("button:eq(1)").html("姓名不合法或已存在！");
            $("button:eq(1)").css("display","inline-block");
            $("button:eq(1)").css("color","red");
            $("button:eq(1)").css("font-size","28");
            return false;
        }
        $.getJSON("/delivery/findByDeliveryName.do",{deliveryName:str},function (data) {
            if(data["msgCode"]==400){
                $("button:eq(1)").html("正确");
                $("button:eq(1)").css("display","inline-block");
                $("button:eq(1)").css("color","green");
                $("button:eq(1)").css("font-size","28");
                return true;
            }else {
                $("button:eq(1)").html("已存在");
                $("button:eq(1)").css("display","inline-block");
                $("button:eq(1)").css("color","red");
                $("button:eq(1)").css("font-size","28");
            }
            return false;
        });
    }
    function phoneTest () {
        var str = $("input:eq(4)").val();
        str=$.trim(str);
        console.log(str);
        var ret = /^(13[0-9]|14[5|7]|15[0|1|2|3|4|5|6|7|8|9]|18[0|1|2|3|5|6|7|8|9])\d{8}$/;
        if (!ret.test(str)) {
            console.log(0);
            $("button:eq(2)").html("手机号不合法或已存在！");
            $("button:eq(2)").css("display","inline-block");
            $("button:eq(2)").css("color","red");
            $("button:eq(2)").css("font-size","28");
            return false;
        }
        $.getJSON("/delivery/findByPhone.do",{phone:str},function (data) {
            if(data["msgCode"]==400){
                $("button:eq(2)").html("正确");
                $("button:eq(2)").css("display","inline-block");
                $("button:eq(2)").css("color","green");
                $("button:eq(2)").css("font-size","28");
                return true;
            }else {
                $("button:eq(2)").html("已存在");
                $("button:eq(2)").css("display","inline-block");
                $("button:eq(2)").css("color","red");
                $("button:eq(2)").css("font-size","28");
                return true;
            }
            return false;
        });
    }
</script>
</body>
</html>
